<html>
<head>
	<title>My Form</title>
	<link href="<?php echo  base_url();?>public/css/bootstrap.min.css" rel="stylesheet">
	<link href="<?php echo  base_url();?>public/css/bootstrap-theme.min.css" rel="stylesheet">
	<link href="<?php echo  base_url();?>public/css/style.css" rel="stylesheet">
	<script charset="utf-8" src="<?php echo  base_url();?>public/js/jquery-3.1.0.min.js"></script>
	<script charset="utf-8" src="<?php echo  base_url();?>public/js/bootstrap.min.js"></script>
</head>
<body>
	<?php $this->load->view('admin/header')?>
	<div class="container">
		<h1>文章标题<a href="<?php echo site_url("/admin/article/add")?>" class="btn btn-success pull-right">添加标题</a></h1>
		<table class="table table-bordered table-hover table-condensed">
			<tr>
				<td>标题</td>
				<td>访问时间</td>
				<td>访问人数</td>
				<td>是否推荐</td>
				<td>操作</td>
			</tr>
		<?php if(empty($articles)){?>
			<tr>
				<td colspan="9" class="empty">没有数据</td>
			</tr>
		<?php }?>	
			<?php foreach ($articles as $a) {?>
			<tr>
				<td>
					<a href="<?php echo base_url().'index.php/article/view/'.$a->id?>"><?= $a->title?></a>
				</td>
				<td>
					<?= date("Y-m-d H:i:s",$a->create_time);?></td>
				<td>
					<?php echo $a->view ;?></td>
				<td>
					<?php echo $a->recommend==1?"<span class='btn btn-success btn-xs'>已推荐</span>":"";?></td>
				<td>
				<?php if($a->recommend==1) {?>
					<a class="btn btn-info btn-xs recommend" href="<?php echo site_url("admin/article/recommend/$a->id/0")?>">取消推荐</a>&nbsp;
				<?php }else{ ?>
					<a class="btn btn-info btn-xs recommend" href="<?php echo site_url("admin/article/recommend/$a->id/1")?>">推荐</a>&nbsp;
					<?php }?>
					<a class="btn btn-warning btn-xs edit" href="<?php echo site_url("admin/article/edit/$a->id")?>">修改</a>&nbsp;
					<a class="btn btn-danger btn-xs del" class="del" href="<?php echo site_url("/admin/article/del/$a->id")?>">删除</a>
				</td>
			</tr>
			<?php } ?>
		</table>
		<?php echo $this->pagination->create_links();?>
	</div>
	<div id="myModal" class="modal fade">
	    <div class="modal-dialog  modal-lg">
		    <div class="modal-content">
		      	<div class="modal-header">
		        	<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        <h4 class="modal-title">Modal title</h4>
		     	 </div>
		      	<div class="modal-body">
		        
		      	</div>
		      	<div class="modal-footer">
		        	<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
		        	<button type="button" class="btn btn-primary">Save changes</button>
		      	</div>
		    </div>
		</div>
	</div>
	<script type="text/javascript">
		$(function(){
			$(".recommend").click(function(){
				var href=$(this).attr('href');
				$.get(href,function(){
					location.reload();
				});
				return false;
			});
			$(".edit").click(function(){
				$('#myModal').modal('show');
				$.get($(this).attr('href'),function(data){
					$('#myModal .modal-body').html(data);	
				})
				return false;	//jquery中防止页面跳转
			});
			$(".del").click(function(){
				if(confirm("确认删除")){
					var href=$(this).attr('href');
					$.get(href,function(){
						location.reload();
					});
				}	
				return false;
			});
		});
	</script>
</body>
</html>